﻿using IMeiWeiWebService.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IMeiWeiWebService.Extensions;

namespace IMeiWeiWebService.Providers
{
    public class ArticleProvider
    {
        IMeiWei.BLL.article bll_article = new IMeiWei.BLL.article();
        IMeiWei.BLL.articleimg bll_articleimg = new IMeiWei.BLL.articleimg();

        public IList<IMeiWei.Model.article> GetAllArticles()
        {
            var models = bll_article.GetModelList("1=1");
            return models;
        }

        public ArticleViewModel GetArticleById(string id)
        {
            ArticleViewModel result = new ArticleViewModel();

            var model = bll_article.GetModelList("Id='" + id + "'").FirstOrDefault();

            if (null != model)
            {
                var imgModel = bll_articleimg.GetModelList("Article_Id ='" + model.Id + "'").FirstOrDefault();

                result = model.ToArticleViewModel(imgModel.ArticleImgName);
            }

            return result;
        }
    }
}